package me.send.business.service.mapper.provider;

import java.util.Map;

public class WalletProvider {
	public String chargeInDetails(Map<String, Object> param) {
		String sql = "select walletLogId id,changeDesc,changeTime,tipAmount total "
				+ "from broker_wallet_log where 1=1 ";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			int lastid = (Integer) param.get("lastId");
			sql += "and brokerId=" + popid + " and tipAmount>0 ";
			if (lastid != 0) {// 首页
				sql += "and walletLogId<" + lastid;
			}
			sql += " order by walletLogId desc limit " + size;
		}
		return sql;
	}

	public String chargeInPage(Map<String, Object> param) {
		String sql = "";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			sql += "select count(*)/" + size + "+1 "
					+ "from broker_wallet_log where 1=1 ";
			sql += "and brokerId=" + popid + " and tipAmount>0 ";
		}
		return sql;
	}

	public String buyDetails(Map<String, Object> param) {
		String sql = "select walletLogId id,changeDesc,changeTime,purchaseAmount total "
				+ "from broker_wallet_log where 1=1 ";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			int lastid = (Integer) param.get("lastId");
			sql += "and brokerId=" + popid + " and purchaseAmount>0 ";
			if (lastid != 0) {// 首页
				sql += "and walletLogId<" + lastid;
			}
			sql += " order by walletLogId desc limit " + size;
		}
		return sql;
	}

	public String buyPage(Map<String, Object> param) {
		String sql = "";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			sql += "select count(*)/" + size + "+1 "
					+ "from broker_wallet_log where 1=1 ";
			sql += "and brokerId=" + popid + " and purchaseAmount>0 ";
		}
		return sql;
	}

	public String allDetails(Map<String, Object> param) {
		String sql = "select walletLogId id,changeDesc,changeTime,purchaseAmount+tipAmount total "
				+ "from broker_wallet_log where 1=1 ";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			int lastid = (Integer) param.get("lastId");
			sql += "and brokerId=" + popid;
			if (lastid != 0) {// 首页
				sql += " and walletLogId<" + lastid;
			}
			sql += " order by walletLogId desc limit " + size;
		}
		return sql;
	}

	public String allPage(Map<String, Object> param) {
		String sql = "";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			sql += "select count(*)/" + size + "+1 "
					+ "from broker_wallet_log where 1=1 ";
			sql += "and brokerId=" + popid;
		}
		return sql;
	}

	public String withdrawDetails(Map<String, Object> param) {
		String sql = "select walletLogId id,changeDesc,changeTime,purchaseAmount+tipAmount total "
				+ "from broker_wallet_log where 1=1 ";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			int lastid = (Integer) param.get("lastId");
			sql += "and brokerId=" + popid
					+ " and (purchaseAmount<0 or tipAmount<0)";
			if (lastid != 0) {// 首页
				sql += " and walletLogId<" + lastid;
			}
			sql += " order by walletLogId desc limit " + size;
		}
		return sql;
	}

	public String withdrawPage(Map<String, Object> param) {
		String sql = "";
		if (param != null) {
			int popid = (Integer) param.get("popid");
			int size = (Integer) param.get("size");
			sql += "select count(*)/" + size + "+1 "
					+ "from broker_wallet_log where 1=1 ";
			sql += "and brokerId=" + popid
					+ " and (purchaseAmount<0 or tipAmount<0)";
		}
		return sql;
	}
}
